<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<HTML>
<HEAD>
  <meta http-equiv="Content-Language" content="zh-cn">
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <LINK href="${pageContext.request.contextPath}/css/Style1.css" type="text/css" rel="stylesheet">
  <script src="${pageContext.request.contextPath}/js/jquery-2.1.4.min.js"
          type="text/javascript"></script>
</HEAD>

<body>
<!--  -->
<form:form action="${pageContext.request.contextPath}/" method="post" commandName="product"
           enctype="multipart/form-data">
  &nbsp;
  <table cellSpacing="1" cellPadding="5" width="100%" align="center" bgColor="#eeeeee"
         style="border: 1px solid #8ba7e3" border="0">
    <tr>
      <td class="ta_01" align="center" bgColor="#afd1f3" colSpan="4"
          height="26">
        <strong><STRONG>编辑商品</STRONG>
        </strong>
      </td>
    </tr>

    <tr>
      <form:hidden path="pid"/>
      <td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
        商品名称：
      </td>
      <td class="ta_01" bgColor="#ffffff">
        <form:input path="name"/>
      </td>
      <td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
        是否热门：
      </td>
      <td class="ta_01" bgColor="#ffffff">
          <%--<select id="ddlregtype">--%>
          <%--<c:if test="${is_hot == 1}">--%>
          <%--<option value="1" selected="selected">是</option>--%>
          <%--<option value="0">否</option>--%>
          <%--</c:if>--%>
          <%--<c:if test="${is_hot != 1}">&ndash;%&gt;--%>
          <%--<option value="1">是--%>
          <%--<option value="0" selected="selected">否--%>
          <%--</c:if>--%>
          <%--</select>--%>
        <form:select path="isHot" items="${isHot}"/>
      </td>
    </tr>
    <tr>
      <td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
        市场价格：
      </td>
      <td class="ta_01" bgColor="#ffffff">
        <form:input path="marketPrice"/>
      </td>
      <td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
        商城价格：
      </td>
      <td class="ta_01" bgColor="#ffffff">
        <form:input path="shopPrice"/>
      </td>
    </tr>
    <tr>
      <td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
        商品图片：
      </td>
      <td class="ta_01" bgColor="#ffffff" colspan="3">
        <div class="container">
          <img id="img"
               src="${pageContext.request.contextPath}/${product.image}"
               alt="${product.name}">
          <input type="file" id="photo" name="upload"/>
        </div>
      </td>
    </tr>
    <tr>
      <td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
        所属分类：
      </td>
      <td class="ta_01" bgColor="#ffffff" colspan="3">
        <form:select path="cid" items="${list}"/>
          <%--<span>${product.category.cname}</span>--%>
      </td>
    </tr>
    <tr>
      <td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
        商品描述：
      </td>
      <td class="ta_01" bgColor="#ffffff" colspan="3">
        <form:textarea path="desc" cols="30" rows="5"/>
      </td>
    </tr>
    <tr>
      <td class="ta_01" style="WIDTH: 100%" align="center"
          bgColor="#f5fafe" colSpan="4">
        <button type="button" id="submit" onclick="Productupdate()" value="确定"
                class="button_ok">
          &#30830;&#23450;
        </button>

          <%--<FONT face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT>--%>
          <%--<button type="reset" value="重置" class="button_cancel">&#37325;&#32622;</button>--%>

        <FONT face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT>
        <INPUT class="button_ok" type="button" onclick="goback()" value="返回"/>
        <span id="Label1"></span>
      </td>
    </tr>
  </table>
</form:form>

</body>

<script>
  function goback() {
    location.href = "${pageContext.request.contextPath}/admin/adminFindAllProduct.do?page=0";
  }

  function Productupdate() {
    $.ajax({
      url: "${pageContext.request.contextPath}/admin/adminProductUpdate.do",
      type: "post",
      data: {
        image: $("#photo").val(),
        pid: $("#pid").val(),
        name: $("input[name='name']").val(),
        marketPrice: $("input[name='marketPrice']").val(),
        shopPrice: $("input[name='shopPrice']").val(),
        is_hot: $("#is_hot").val(),
        cid: $("#cid").val(),
        desc: $("#desc").val()
      },
      success: function (d) {
        if (d.status == 0) {
          location.href = "/admin/adminFindAllProduct.do?page=0";
        }
      }

    })

  }

  $("#submit").click = function () {
    Productupdate();
  };

</script>

</HTML>